package com.jiangyg.mall.member.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.member.dto.MemberLoginLogDTO;
import com.jiangyg.mall.member.service.MemberLoginLogService;
import com.jiangyg.mall.member.vo.MemberLoginLogVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：会员登录记录控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:33:09
 */
@RestController
@RequestMapping("/member/memberLoginLog")
public class MemberLoginLogController {

    /**
     * 会员登录记录接口
     */
    private final MemberLoginLogService memberLoginLogService;

    @Autowired
    public MemberLoginLogController(MemberLoginLogService memberLoginLogService) {
        this.memberLoginLogService = memberLoginLogService;
    }

    /**
     * 功能描述：会员登录记录分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页会员登录记录
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<MemberLoginLogVO>> select(HttpServletRequest request, @RequestBody Pagination<MemberLoginLogVO> pagination) throws Exception {
        return Result.ok(memberLoginLogService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改会员登录记录
     *
     * @param request 请求
     * @param dto     会员登录记录
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated MemberLoginLogDTO dto) throws Exception {
        return Result.saveOrUpdate(memberLoginLogService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取会员登录记录
     *
     * @param request 请求
     * @param memberLoginLogId  会员登录记录ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<MemberLoginLogVO> info(HttpServletRequest request, @RequestParam(name = "memberLoginLogId") Long memberLoginLogId) throws Exception {
        return Result.ok(memberLoginLogService.selectById(memberLoginLogId));
    }

    /**
     * 功能描述：删除会员登录记录
     *
     * @param request 请求
     * @param memberLoginLogIds 批量删除的会员登录记录ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "memberLoginLogIds") List<Long> memberLoginLogIds) {
        return Result.delete(memberLoginLogService.delete(memberLoginLogIds));
    }

}
